package domd1;

public class Main {
    public static void main(String[] args) {
        String s1 = "hello world !!!";
        //将字符串按照空格全部拆分
        String[] a = s1.split(" ");
        for (String x : a) {
            System.out.println(x);
        }
        System.out.println("=======");
        //将字符串以指定的格式，拆分成n组
        String[] s2 = s1.split(" ", 2);
        for (String y : s2) {
            System.out.println(y);
        }
        System.out.println("=======");
        //拆分IP地址
        String s3 = "192.168.128.128";
        String[] s4 = s3.split("\\.");
        for (String z : s4) {
            System.out.println(z);
        }
        //多次拆分
        String str = "name=zhangsan&age=18";
        String[] result = str.split("&");
        for (int i = 0; i < result.length; i++) {
            String[] temp = result[i].split("=");
            System.out.println(temp[0] + " = " + temp[1]);
        }
    }
}
